/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package entities;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author riccardo
 */
@Entity
@Table(name = "COMPAGNIA")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Compagnia.findAll", query = "SELECT c FROM Compagnia c"),
    @NamedQuery(name = "Compagnia.findByIdCOMPAGNIA", query = "SELECT c FROM Compagnia c WHERE c.idCOMPAGNIA = :idCOMPAGNIA"),
    @NamedQuery(name = "Compagnia.findByNome", query = "SELECT c FROM Compagnia c WHERE c.nome = :nome"),
    @NamedQuery(name = "Compagnia.findByRecapito", query = "SELECT c FROM Compagnia c WHERE c.recapito = :recapito")})
public class Compagnia implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @NotNull
    @Column(name = "idCOMPAGNIA")
    private Integer idCOMPAGNIA;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 255)
    @Column(name = "nome")
    private String nome;
    @Size(max = 255)
    @Column(name = "recapito")
    private String recapito;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "compagnia")
    private Collection<Volo> voloCollection;

    public Compagnia() {
    }

    public Compagnia(Integer idCOMPAGNIA) {
        this.idCOMPAGNIA = idCOMPAGNIA;
    }

    public Compagnia(Integer idCOMPAGNIA, String nome) {
        this.idCOMPAGNIA = idCOMPAGNIA;
        this.nome = nome;
    }

    public Integer getIdCOMPAGNIA() {
        return idCOMPAGNIA;
    }

    public void setIdCOMPAGNIA(Integer idCOMPAGNIA) {
        this.idCOMPAGNIA = idCOMPAGNIA;
    }

    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

    public String getRecapito() {
        return recapito;
    }

    public void setRecapito(String recapito) {
        this.recapito = recapito;
    }

    @XmlTransient
    public Collection<Volo> getVoloCollection() {
        return voloCollection;
    }

    public void setVoloCollection(Collection<Volo> voloCollection) {
        this.voloCollection = voloCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idCOMPAGNIA != null ? idCOMPAGNIA.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Compagnia)) {
            return false;
        }
        Compagnia other = (Compagnia) object;
        if ((this.idCOMPAGNIA == null && other.idCOMPAGNIA != null) || (this.idCOMPAGNIA != null && !this.idCOMPAGNIA.equals(other.idCOMPAGNIA))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entities.Compagnia[ idCOMPAGNIA=" + idCOMPAGNIA + " ]";
    }
    
}
